class Stack:
    def __init__(self):
        self.items = []

    def push(self, item):
        self.items.append(item)

    def pop(self):
        if not self.is_empty():
            return self.items.pop()
        return None

    def is_empty(self):
        return len(self.items) == 0

    def peek(self):
        if not self.is_empty():
            return self.items[-1]
        return None

def is_valid_parentheses(s):
    """验证仅含()的字符串是否有效"""
    stack = Stack()
    for char in s:
        if char == '(':
            stack.push(char)
        else:  # char == ')'
            if stack.is_empty() or stack.pop() != '(':
                return False
    # 遍历结束后栈必须为空
    return stack.is_empty()

# 测试
if __name__ == "__main__":
    print(is_valid_parentheses("()()"))  # 输出: True
    print(is_valid_parentheses("(()"))   # 输出: False
    print(is_valid_parentheses(")("))    # 输出: False